package com.acme.bankapp.domain.bank;

import com.acme.bankapp.exceptions.bank.NotEnoughFundsException;

import java.io.Serializable;

public abstract class AbstractAccount implements Account, Serializable {
    static int currentMaxId = 0;

    protected int id;
    protected double balance;

	public AbstractAccount(double amount) {
        if (balance < 0) {
            throw new IllegalArgumentException("balance is less then zero");
        }
        this.balance = amount;
        currentMaxId++;
        this.id = currentMaxId;
	}

	public double getBalance() {
		return this.balance;
	}

    public long decimalBalance() {
        return Math.round(this.balance);
    }

    public int getId() {
        return this.id;
    }

	public abstract void deposit(double amount);

	public abstract void withdraw(double amount) throws NotEnoughFundsException;

    public abstract double maximumAmountToWithdraw();

    public String toString() {
        return "id=" + id + ", balance=" + this.decimalBalance();
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        AbstractAccount that = (AbstractAccount) o;

        return id == that.id;

    }

    public int hashCode() {
        return id;
    }
}
